package com.hotel.reservation.controller.before;

import com.hotel.reservation.dao.ReserveDao;
import com.hotel.reservation.po.ReservePo;
import com.hotel.reservation.po.RoomPo;
import com.hotel.reservation.service.ReserveService;
import com.hotel.reservation.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @version 0.1
 * @Author: oliver chen
 * @Description:
 * @Date:Create：in 2021/8/1 14:40
 * @Modified By：
 */
@Controller
@RequestMapping("/before/reserve")
public class BeforeReserveController {
    @Autowired
    private ReserveService reserveService;

    @Autowired
    private RoomService roomService;

    @RequestMapping("/insertInfo")
    public String insertInfo(ReservePo reserve){
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//可以方便地修改日期格式
        String nowDate = dateFormat.format( now );
        reserve.setReserveNowTime(nowDate);
        reserve.setReserveState(0);
        int isSuccess = reserveService.insertInfo(reserve);
        if (isSuccess==1){
            RoomPo roomPo = roomService.selectByRoomId(reserve.getReserveRoomId());
            roomPo.setRoomState(1);//已预订
            roomService.alterARoom(roomPo);
            return "forward:/hotel/main";
        }else return "false!!";
    }
}
